//
//  LCMiddleVC.m
//  LongChain
//
//  Created by FengZi on 2018/4/9.
//  Copyright © 2018年 FengZi. All rights reserved.
//

#import "LCMiddleVC.h"

@interface LCMiddleVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) NSArray *devices;

@end

@implementation LCMiddleVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self lc_loadDeviceListData];

}
//  获取设备列表
- (void)lc_loadDeviceListData {
    
//    [self showHudInView:self.view hint:@""];
    [[LCNetwork shareInstance]lc_getNetworkWithURL:@"/api/v0/device/bound" responseSuccess:^(id resultCode, id resultParameter) {
        NSString *resultCodeStr = [NSString stringWithFormat:@"%@",resultCode];
        if ([resultCodeStr isEqualToString:@"0"]) {
            LCLog(@"resultParameter = %@",resultParameter);
            
            NSArray *data = resultParameter[@"data"];
            self.devices = data;
            
        }
    } responseFail:^(id resultCode, NSError *error) {
        
    }];
    
}


- (IBAction)addCloud:(id)sender {
    
    LCLog(@"云添加");
    [self showHint:@"功能开发中"];
    [self removeFromSubperView];

//    [UIApplication sharedApplication].keyWindow.rootViewController = loginVC;
    UINavigationController *nav = [UIApplication sharedApplication].keyWindow.rootViewController.navigationController;
    
    [nav pushViewController:[UIViewController new] animated:YES];


}


- (IBAction)addPhoto:(id)sender {
    LCLog(@"添加照片");
    [self postUploadNotificationWithType:UploadTypePhoto];
    
}


- (IBAction)addFolders:(id)sender {
    
    LCLog(@"添加文件夹");

}

- (IBAction)addVideo:(id)sender {
    LCLog(@"添加视频");
    [self postUploadNotificationWithType:UploadTypeVideo];

}

- (void)postUploadNotificationWithType:(UploadType)type {
    
    [self removeFromSubperView];
    if (self.devices) {
        NSDictionary *uploadTypeDic = @{@"type":@(type),@"devices":self.devices};
        [[NSNotificationCenter defaultCenter]postNotificationName:@"uploadFile" object:self userInfo:uploadTypeDic];

    }
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"middleHeader" forIndexPath:indexPath];
        return header;
    }else if ([kind isEqualToString:UICollectionElementKindSectionFooter]){
        UICollectionReusableView *footer = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"middleFooter" forIndexPath:indexPath];
        return footer;
    }
    return nil;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"middleCell" forIndexPath:indexPath];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 4;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(SWidth, 100);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(SWidth / 3, 100);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    return  CGSizeMake(SWidth, 100);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    [self.view removeFromSuperview];
    
    
    NSLog(@"点击");
}
- (IBAction)dismiss:(id)sender {
    
    [self removeFromSubperView];
}

- (void)removeFromSubperView {
    [self.view removeFromSuperview];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
